//
//  RecommendNewViewController.m
//  DA_V
//
//  Created by 周季阳 on 15/4/28.
//  Copyright (c) 2015年 zhouhai. All rights reserved.
//

#import "RecommendNewViewController.h"
#import "InterFace.h"
#import "UIViewAdditions.h"
#import "WriteInfoViewController.h"
#import "UMSocial.h"
#import "YoungAllData.h"
#import "UIImageView+WebCache.h"
#import "UMSocialSnsService.h"
#import "UMSocialWechatHandler.h"
#import "UMSocialQQHandler.h"
#import "GMDCircleLoader.h"
@interface RecommendNewViewController ()<UMSocialDataDelegate,UMSocialUIDelegate,YoungDelegate>
@property(nonatomic,retain)NSString *zUrl;
@property(nonatomic,retain)NSString *zTitle;
@end

@implementation RecommendNewViewController
@synthesize levelNumber,zUrl,zTitle;
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBarHidden=YES;
    
    self.view.backgroundColor = [self colorWithHexString:@"#F5F5F5"];
    
    YoungAllData *data = [[YoungAllData alloc]init];
    data.delegate = self;
    [data gainQrcode:[[NSUserDefaults standardUserDefaults] objectForKey:@"userID"] andLevelID:levelNumber];
    [GMDCircleLoader setOnView:self.view withTitle:@"加载中···" animated:YES];

}
#pragma mark - 二维码回调
-(void)qrcode:(NSDictionary *)sign{
    [GMDCircleLoader hideFromView:self.view animated:YES];
    if ([[sign objectForKey:@"status"] isEqualToString:@"success"]) {
    zUrl = [NSString stringWithFormat:@"%@",[[sign objectForKey:@"data"] objectForKey:@"ShareUrl"]];
    zTitle = [NSString stringWithFormat:@"%@",[[sign objectForKey:@"data"] objectForKey:@"Subject"]];

    [self initUI:[[sign objectForKey:@"data"] objectForKey:@"ImageUrl"]];
        [self initNav];
        navTitle.text = @"选择推荐方式";

    }else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:[sign objectForKey:@"reason"] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }
}
#pragma mark - 回调失败
-(void)requistFail{
    [GMDCircleLoader hideFromView:self.view animated:YES];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"网络异常,无法加载数据" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
}
#pragma mark - initUI
-(void)initUI:(NSString *)data{
   
    

    UIView *backgroundView;
    UIScrollView *scrollView;
    if (SCREEN_HEIGHT < 568) {
        backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT*0.65)];
        backgroundView.backgroundColor = [UIColor whiteColor];
        backgroundView.userInteractionEnabled = YES;
        scrollView= [[UIScrollView alloc] initWithFrame:CGRectMake(0, navView.bottom+10, SCREEN_WIDTH, SCREEN_HEIGHT)];
        scrollView.contentSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT *1.2);
        [scrollView addSubview:backgroundView];
        [self.view addSubview:scrollView];
    } else {
        backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, navView.bottom+10, SCREEN_WIDTH, SCREEN_HEIGHT*0.65)];
        backgroundView.backgroundColor = [UIColor whiteColor];
        backgroundView.userInteractionEnabled = YES;
    [self.view addSubview:backgroundView];
    }
    
    UIButton *backNewsButto1n = [UIButton buttonWithType:UIButtonTypeCustom];
    backNewsButto1n.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height-((0.15625*SCREEN_WIDTH)),SCREEN_WIDTH/2, (0.15625*SCREEN_WIDTH));
    [backNewsButto1n addTarget:self action:@selector(shareAgentButton) forControlEvents:UIControlEventTouchUpInside];
    [backNewsButto1n setBackgroundImage:[UIImage imageNamed:@"资料-推广素材---内容页_02"] forState:UIControlStateNormal];
    [self.view addSubview:backNewsButto1n];
    NSLog(@"%2f",SCREEN_WIDTH);
    
    UIButton *backNewsButton = [UIButton buttonWithType:UIButtonTypeCustom];
    backNewsButton.frame = CGRectMake(SCREEN_WIDTH/2, [UIScreen mainScreen].bounds.size.height-((0.15625*SCREEN_WIDTH)),SCREEN_WIDTH/2, (0.15625*SCREEN_WIDTH));
    [backNewsButton addTarget:self action:@selector(clickBackBtn) forControlEvents:UIControlEventTouchUpInside];
    [backNewsButton setBackgroundImage:[UIImage imageNamed:@"资料-推广素材---内容页_03"] forState:UIControlStateNormal];
    [self.view addSubview:backNewsButton];
    
    
    
    UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-SCREEN_WIDTH*0.675)/2, 40,SCREEN_WIDTH*0.675, SCREEN_WIDTH*0.675)];
    [imageView2 sd_setImageWithURL:[NSURL URLWithString:data] placeholderImage:nil];
    imageView2.tag = 123;
    //    imageView2.backgroundColor = [UIColor orangeColor];
    
    [backgroundView addSubview:imageView2];
    
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, imageView2.bottom+10, self.view.frame.size.width, 40)];
    label.text = @"扫描二维码";
    label.textAlignment = NSTextAlignmentCenter;
    [backgroundView addSubview:label];
    
    UIButton *shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
    shareButton.frame = CGRectMake(0.0625*SCREEN_WIDTH, label.bottom+10,SCREEN_WIDTH*0.875, SCREEN_WIDTH*0.125);
    [shareButton addTarget:self action:@selector(shareAgentButton) forControlEvents:UIControlEventTouchUpInside];
    [shareButton setImage:[UIImage imageNamed:@"推荐新微商_07"] forState:UIControlStateNormal];
    [backgroundView addSubview:shareButton];
    
    UIButton *newBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    newBtn.frame = CGRectMake(0.0625*SCREEN_WIDTH, backgroundView.bottom+20,SCREEN_WIDTH*0.875, SCREEN_WIDTH*0.125);
    [newBtn addTarget:self action:@selector(wirteAgentButton) forControlEvents:UIControlEventTouchUpInside];
    [newBtn setImage:[UIImage imageNamed:@"推荐新微商_10"] forState:UIControlStateNormal];
    //    [shareButton setImage:[UIImage imageNamed:@"backBtnSel"] forState:UIControlStateHighlighted];
     if (SCREEN_HEIGHT < 568)
     {
     newBtn.frame = CGRectMake(0.0625*SCREEN_WIDTH, shareButton.bottom+20,SCREEN_WIDTH*0.875, SCREEN_WIDTH*0.125);
         [scrollView addSubview:newBtn];
     } else {
     newBtn.frame = CGRectMake(0.0625*SCREEN_WIDTH, backgroundView.bottom+20,SCREEN_WIDTH*0.875, SCREEN_WIDTH*0.125);
         [self.view addSubview:newBtn];
     }
    
    
    
}
#pragma mark - 填写信息
-(void)wirteAgentButton{
    WriteInfoViewController *wirte = [[WriteInfoViewController alloc]init];
    wirte.levelNumber = levelNumber;
    [self.navigationController pushViewController:wirte animated:YES];
}
#pragma mark - 分享到
-(void)shareAgentButton{
    [UMSocialSnsService presentSnsIconSheetView:self
                                         appKey:@"507fcab25270157b37000010"
                                      shareText:zTitle
                                     shareImage:[UIImage imageNamed:@"ios-57.png"]
                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToWechatTimeline,UMShareToWechatSession,UMShareToQQ,nil]
                                       delegate:self];
    
   
    
//    [UMSocialQQHandler setQQWithAppId:@"wxe42555fc43cf3c1d" appKey:@"a2348ea607d68e3995472e1cd4d56012" url:zUrl];
    
     [UMSocialWechatHandler setWXAppId:@"wxe42555fc43cf3c1d" appSecret:@"a2348ea607d68e3995472e1cd4d56012" url:zUrl];
}
-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response{
    NSLog(@"%@",response);
    NSDictionary *dic = (NSDictionary *)response;
    if ([[[dic objectForKey:@"data"] objectForKey:@"responseCode"]isEqualToString:@"200"]) {
        NSLog(@"success");
    }else{
        NSLog(@"Fail");
    }
}
#pragma mark - 分享&返回
-(void)detailViewBackAction{

}
-(void)detailViewBackAction1{
    
}

#pragma mark - 返回
-(void)clickBackBtn{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)viewWillDisappear:(BOOL)animated {
    self.tabBarController.tabBar.hidden = NO;
}
-(void)viewWillAppear:(BOOL)animated{
    self.tabBarController.tabBar.hidden = YES;
    
}
/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
